<?php echo $this->element('displayHeader'); ?>
<div class="toolbar"><?php echo $this->element('toolbar', array('buttons' => array('add', 'search', 'refresh'))); ?></div>

<?php if (empty($this->data)) : // ถ้าไม่มีข้อมูล ?>
<?php echo $this->element('dataNotFound'); ?>
<? else : // ถ้ามีข้อมูล ?>
<?php $paginator->options(array('update' => 'content', 'indicator' => 'indicator')); ?>
<?php echo $this->element('dataCaptionLimit'); ?>
<?php $cur = $paginator->counter(array('format' => '%start%')); ?>

<table class="data">
    <thead>
        <tr>
            <th class="no"><?php echo $paginator->sort('No', 'id'); ?></th>
            <th><?php echo $paginator->sort('Dispatch no', 'SDH.dispatch_no'); ?></th>
            <th width="100px"><?php echo $paginator->sort('Dispatch date', 'SDH.dispatch_date'); ?></th>
            <th><?php echo $paginator->sort('Customer', 'Customer.name'); ?></th>
            <th><?php echo $paginator->sort('Site', 'Site.name'); ?></th>
            <th><?php echo $paginator->sort('Delivered To', 'SDH.deliveree'); ?></th>
            <th width="150px"><?php echo $paginator->sort('Dispatch Status', 'Dispatch.title'); ?></th>
            <th width="100px"><?php echo $paginator->sort('Dispatch by', 'User.name'); ?></th>
            <th class="action">&nbsp;</th>
        </tr>
    </thead>
    <tbody>
        <?php foreach($this->data as $key => $data): ?>
        <?php
        $tableCell = array();
        $tableCell[] = $cur++;
        $tableCell[] = $data['SDH']['dispatch_no'];
        $tableCell[] = $data['SDH']['dispatch_date'];
        $tableCell[] = $data['Customer']['name'];
        $tableCell[] = $data['Site']['name'];
        $tableCell[] = $data['SDH']['delivered_to'];
                if ($data['SDH']['is_dispatch_return'] == true) {
            $tableCell[] = $data['DispatchStatus']['title'] . '&nbsp;' .
                    $html->link($html->image('icon/return.png'),
                    '/supplier_dispatch_returns/view/return_dispatch_id:' . $data['SDH']['id'] . '/' . strtotime('now'),
                    array('target' => '_blank', 'title' => 'This Dispatch is already returned.'), null, false);
        } elseif ($data['SDH']['dispatch_status_id'] == DispatchStatus::ON_DISPATCH_STATUS || $data['SDH']['dispatch_status_id'] == DispatchStatus::PARTIAL_CONSIGNED_STATUS) {
            $tableCell[] = $data['DispatchStatus']['title'] . '&nbsp;' .
                    $html->link($html->image('icon/return2.png'),
                    '/supplier_dispatch_returns/view/dispatch_id:' . $data['SDH']['id'],
                    array('target' => '_blank', 'title' => 'Return this Dispatch'), null, false);
        } else {
            $tableCell[] = $data['DispatchStatus']['title'];
        }
        $tableCell[] = $data['User']['name'];
        $tableCell[] = $ajax->link($html->image('icon/edit.png', array('title' => 'edit', 'alt' => 'edit')), 'view/' . $data['SDH']['id'], array('indicator' => 'indicator', 'update' => 'content'), null, false);
        echo $html->tableCells($tableCell, array('class' => 'odd-cell'), array('class' => 'even-cell'));
        ?>
        <?php endforeach; ?>
    </tbody>
</table>

<?php echo $this->element('paging'); ?>
<? endif; ?>